// 引入vue实例 和 路由
import Vue from 'vue'
import VueRouter from 'vue-router'

// 使用路由插件
Vue.use(VueRouter)

// 创建路由规则
const routes = [
  {
    // 主页
    path: '/',
    component: () => import('../views/index/index.vue')
  },
  {
    // 房产经纪
    path: '/agent',
    component: () => import('../views/agent/index.vue')
  },

  // {
  //   // 关于我们
  //   path: '/about',
  //   component: () => import('../views/about/index.vue')
  // },
  // 地产分类
  {
    path: '/category',
    name: '/category',
    component: () => import('../views/category/index.vue'),
    redirect: '/category/categoriers',
    children: [
      // 分类
      {
        path: 'categoriers',
        name: 'categoriers',
        component: () => import('../views/category/realEstateCategory.vue')
      },
      // 列表
      {
        path: 'list',
        name: 'list',
        component: () => import('../views/category/realEstateList.vue')
      },
      // 详情
      {
        path: 'detail',
        name: 'detail',
        component: () => import('../views/category/realEstateDetail.vue')
      }
    ]
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }
  // { path: '*', redirect: '/404' }
]

// 创建路由对象 -  传入规则
const createRouter = () =>
  new VueRouter({
    routes
  })

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
  console.log(72, routes)
}

export default router
